# encoding: utf-8
import re
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_unicode
#from mobilephonehelper import operator_helper
from django.contrib.auth.models import User as AuthUser
from django.core.exceptions import ValidationError

from versatileimagefield.fields import VersatileImageField

#from django.conf import settings

import logging
logger = logging.getLogger(__name__)
# logger.info("Log this message")


from usercenter.models import Users
# Create your models here.
ROOM_STATUS = (
    (0, u"可预定"),
    (1, u"未开放"),
)
SMS_STATUS = (
    (0, u"未通知"),
    (1, u"已通知"),
)



YUDINGTIME_STATUS = (
    (0, u"可预定"),
    (1, u"未开放"),
)

ROOM_Weizhi_Xiaoqu= (
    (0, u"团河校区"),
    (1, u"木樨地校区"),
)

Yuding_STATUS = (
    (0, u"待审核"),
    (1, u"审核通过"),
    (20, u"审核未通过"),
)
Yuding_STATUS_DIC = {
	'0':u"待审核",
	'1':u"审核通过",
	'20':u"审核未通过"

}



YudingTime_List = (
    (0, u"上午"),
    (1, u"下午"),
)

class roomLocation(models.Model):
	name=models.CharField(u'位置',max_length=128)

	def __unicode__(self):
		return self.name

	class Meta:
		verbose_name = u"物理位置"
		verbose_name_plural = verbose_name
		#app_label = _(u'管理员－会议室')


class xbRoom(models.Model):
	name=models.CharField(u'会议室名称',max_length=128)
	brief = models.TextField(u'会议室介绍')
	renshu = models.SmallIntegerField(verbose_name=u'可容纳人数',default=20)
	photo =VersatileImageField(u'会议室图片',upload_to='static/images/xbroomimage/')
	xiaoqu = models.SmallIntegerField(choices=ROOM_Weizhi_Xiaoqu, verbose_name=u'所在校区')
	location=models.CharField(u'所在位置',max_length=250)
	status = models.SmallIntegerField(choices=ROOM_STATUS, verbose_name=u'状态')
	telphone=models.CharField(u'联系电话',max_length=20)
	#--------------------
	price= models.CharField(u'价格',max_length=128,null=True, blank=True,default='0')

	create_time = models.DateTimeField(auto_now=True, verbose_name=u'纪录加入日期')

	def __unicode__(self):
		return self.name

	class Meta:
		verbose_name = u"会议室"
		verbose_name_plural = verbose_name
		#app_label = _(u'b')



#---------------------------------------
class yudingTime(models.Model):
	name=models.CharField(u'时间段',max_length=128)
	status=models.SmallIntegerField(u'状态',choices=YUDINGTIME_STATUS,blank=True,default=0)

	def __unicode__(self):
		return self.name

	class Meta:
		verbose_name = u"预约时间段"
		verbose_name_plural = verbose_name
		#app_label = _(u'b')


class yuding(models.Model):
	ydUser=models.ForeignKey(Users,related_name='users_yd', verbose_name=u'预约用户',null=True,blank=True)
	spUser=models.ForeignKey(Users,related_name='users_sp',  verbose_name=u'审批用户',null=True,blank=True)
	ydStatus=models.SmallIntegerField(u'预订状态',choices=Yuding_STATUS,blank=True,default=0)
	ydRoom=models.ForeignKey(xbRoom,verbose_name=u'会议室')
	ydDate=models.DateField(u'预订日期')
	ydTime=models.ManyToManyField(yudingTime,verbose_name=u'预订时段')
	create_time = models.DateTimeField(auto_now=True, verbose_name=u'创建日期')
	shenpi_time = models.DateTimeField(verbose_name=u'审批日期',null=True,blank=True)
	smsStatus=models.SmallIntegerField(u'短信通知',choices=SMS_STATUS,blank=True,default=0)
	beizhu=models.TextField(verbose_name=u'备注',null=True,blank=True)

	#ydTime=models.DateField(verbose_name=u'预订时段')
	
	
	def __unicode__(self):
		return self.ydRoom.name+' '+self.ydUser.user.username

	class Meta:
		verbose_name = u"预订管理"
		verbose_name_plural = verbose_name
		#app_label = _(u'b')


#-------------------------------------------
# 预约用户使用
#-------------------------------------------
class yulan_Room(xbRoom):
	"""
	预订会议室操作，预约用户使用该功能进行预约
	"""

	#objects=chuangjianKWManager()
	class Meta:
		proxy=True
		verbose_name = _(u'预订会议室')
		verbose_name_plural = _(u'预订会议室')
		#app_label = _(u'a')
		#ordering = ["shenhe"]


#===============================

class yulan_Yuding(yuding):
	#objects=yulan_Manager()
	class Meta:
		proxy=True
		#db_table = 'yuding_yuding'
		verbose_name = _(u'我的预订')
		verbose_name_plural = _(u'我的预订')
		#app_label = string_with_title('a','b')
		#managed = False
		#ordering = ["shenhe"]


#-------------------------------------------
# 审批用户使用
#-------------------------------------------
class shenpi_Yuding(yuding):
	#objects=shenpiManager()
	class Meta:
		proxy=True
		#db_table = 'yuding_yuding'
		verbose_name = _(u'审批预订')
		verbose_name_plural = _(u'审批预订')
		#app_label = string_with_title('yudingapp','开始')
		#managed = False
		#ordering = ["shenhe"]


#===============================

class jinri_Yuding(yuding):
	#objects=shenpiManager()
	class Meta:
		proxy=True
		verbose_name = _(u'今日会议室')
		verbose_name_plural = _(u'今日会议室')



#===============================




